<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta charset="utf-8">
		<title>批量添加禁词</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" th:href="@{/center/lib/layui-v2.5.5/css/layui.css}" media="all">
		<link rel="stylesheet" th:href="@{/center/css/public.css}" media="all">
		<script th:src="@{/center/lib/layui-v2.5.5/layui.js}" charset="utf-8"></script>
		<script>
			layui.use(['form'], function() {
				var form = layui.form,
					layer = layui.layer,
					$ = layui.jquery;
		
				//拼接禁词字符串数组
				var list = [];
				var strs=null;
				$('#addBtn').click(function() {
					list.push(JSON.stringify($("#centerKeyword").val()));
					// strs = list.join(",");
					$("#tempWords").val(list);
					$("#centerKeyword").val(null);
					return false;
				});
				//清空待提交列表
				$('#backBtn').click(function() {
					
					$("#tempWords").val(list.pop());
					
					return false;
				});
		
				//监听提交
				form.on('submit(saveBtn)', function(data) {
					// console.log('前端表单数据:'+JSON.stringify('['+'{'+data.field.tempWords+'}'+']'));
					console.log('前端表单数据:'+'['+data.field.tempWords+']');
					$.ajax({
						url: '/center/batchAddWords',
						method: 'POST',
						contentType: 'application/json;charset=utf-8',
						data:'['+data.field.tempWords+']',
						success: function(res) {
							if (res.msg === "批量添加成功") {
								layer.msg(res.msg, {
									icon: 1,
									time: 1000 //1秒关闭（如果不配置，默认是3秒）
								}, function() {
		
									parent.document.location.reload();
								});
		
							} else {
								layer.alert(res.msg);
							}
		
						}
					});
		
					return false;
				});
		
			});
		</script>
		<style>
			body {
            background-color: #ffffff;
        }
    </style>
	</head>
	<body>
		<form class="layui-form layuimini-form">

			<div class="layui-form-item">
				<label class="layui-form-label">禁词名:</label>
				<div class="layui-input-block">
					<input type="text" name="centerKeyword" placeholder="请填写禁词名" class="layui-input" id="centerKeyword">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">待提交列表:</label>
				<div class="layui-input-block">
					<input type="text" name="tempWords" id="tempWords" placeholder="" value="" class="layui-input"
					 style="color: gray;" lay-verify="required">
				</div>
			</div>

			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn layui-btn-normal" id="addBtn">添加到待提交列表</button>
					<button class="layui-btn layui-btn-normal" id="backBtn">删除最近添加的一条数据</button>
					<button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认提交</button>
				</div>
			</div>
		</form>
	
	</body>
</html>
